console.log('zstart')
const Webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const getDevWebpackConfig = require('./webpack.dev.config')
const path = require('path')

const port = process.env.port || 4001
//1.0 server配置
const serverConfig = {
  mode: 'development',
  devServer: {
    static: './dist',
    port: port,
    allowedHosts:'auto',
    client: {
      logging: 'info'
    },
    headers:[
      {
        key: 'x-Custom',
        value: 'foo'
      }
    ],
    proxy: {

    },
    open: true

  }
}

//2.0 webpackConfig

const devWebpackConfig = getDevWebpackConfig()

//2.0 编译器
const compiler = Webpack(devWebpackConfig);

//3.0  创建server
const server = new WebpackDevServer(serverConfig.devServer,compiler)

//4.0 启动
server.startCallback(()=> {
  console.log('Successfully started server on http://localhost:8080');
})

//5.0停止
const stopServer = () => {
  server.stopCallback(()=> {
    console.log('Server stopped.');
  })
}















// const Webpack = require('webpack');
// const WebpackDevServer = require('webpack-dev-server');
// const getDevWebpackConfig = require('./webpack.dev.config')


// //1. server的配置：proxy、port，header等d
// const serverConfig = {}

// //2. webpackConfig

// //3.0 compiler
// const webpackConfig = getDevWebpackConfig()
// const compiler = Webpack(webpackConfig);
// //4.0 创建server
// const devServer = new WebpackDevServer(serverConfig,compiler)

// //5.0 开启server
// //第一种：start
// const runServer = async ()=> {
//   await devServer.start()
// }
// //第二种
// devServer.startCallback(()=> {

// })

